package demo.yml.controller;

import demo.yml.model.MyList;
import demo.yml.model.MyMap;
import demo.yml.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/yml")
@RestController
public class YmlController {

    //server
    @Value("${server.port}")
    private Integer port;

    @RequestMapping("/port")
    public String getPort(){
        return "从配置文件中获取：" + port;
    }

    //string
    @Value("${string.str1}")
    private String str1;

    @Value("${string.str2}")
    private String str2;

    @Value("${string.str3}")
    private String str3;

    @RequestMapping("/string")
    public String getString(){
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        return "从配置文件中获取：";
    }

    //对象
    @Autowired
    private UserInfo userInfo;

    @RequestMapping("/userInfo")
    public String getUserInfo(){
        return "从配置文件中获取对象：" + userInfo;
    }

    //list
    @Autowired
    private MyList list;

    @RequestMapping("/list")
    public String getList(){
        return "从配置文件中获取：" + list + "，size：" +list.getUserInfoList().size();
    }

    //map
    @Autowired
    private MyMap map;

    @RequestMapping("/map")
    public String getMap(){
        return "从配置文件中获取：" + map + "，size:" + map.getHashMap().size();
    }
}
